// Client.cpp: implementation of the CClient class.
//
//////////////////////////////////////////////////////////////////////

#include "Client.h"
#include <KeyParser.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CClient::CClient()
{
	m_Parser = new CKeyParser;
	m_Parser->Reset();
}

CClient::~CClient()
{
	SAFE_DELETE( m_Parser );
}
//----------------------------------------------------------------------------//

int CClient::Init(  )
{

	return 0;

}

int CClient::Recv( char* szPacket, size_t& nPacketSize )
{
	char szBuff[CSock::MAXBUFF];
	size_t nLen = CSock::MAXBUFF;
	memset( szBuff, 0, CSock::MAXBUFF );

	int nRecvSize = m_Socket.Recv( szBuff, nLen );
	if( 0 < nRecvSize )
	{
	

		m_Parser->PacketParse( szBuff, nRecvSize, szPacket, nPacketSize );
		m_Parser->Reset();
	}
		
	return nRecvSize;
}

int CClient::Send( char* szMsg, size_t nLen  )
{
	char szPacket[CSock::MAXBUFF];
	memset( szPacket, 0, CSock::MAXBUFF );
	size_t nPacketSize = 0;
	
	m_Parser->MakePacket( szMsg, nLen, szPacket, nPacketSize );
	
	int nSendSize = m_Socket.Send( szPacket, nPacketSize );
	
	return nSendSize;
}

